Skip to content

feat: add TOML v1.0 serialization support#2828

Open
Thyago-Oliveira-Perez wants to merge 1 commit intomicrosoft:mainfrom
Thyago-Oliveira-Perez:feature/toml-feature
Open

feat: add TOML v1.0 serialization support#2828
Thyago-Oliveira-Perez wants to merge 1 commit intomicrosoft:mainfrom
Thyago-Oliveira-Perez:feature/toml-feature

Conversation

@Thyago-Oliveira-Perez
Copy link
Copy Markdown

   Adds OpenApiTomlWriter (mirrors OpenApiJsonWriter / OpenApiYamlWriter),
   a new OpenApiConstants.Toml constant, and SerializeAsTomlAsync extension
   methods so callers can export an OpenAPI document as TOML.

   Public API declared in PublicAPI.Unshipped.txt; RS0026 suppressed for
   consistency with existing SerializeAsJson/YamlAsync overloads.

Pull Request

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Related Issue(s)

Changes Made

  • Added OpenApiTomlWriter to support writing OpenAPI documents in TOML format
  • Introduced OpenApiConstants.Toml constant
  • Added SerializeAsTomlAsync extension methods (string and stream overloads)
  • Integrated TOML into existing SerializeAsync format selection
  • Declared new public APIs in PublicAPI.Unshipped.txt
  • Suppressed RS0026 for consistency with existing JSON/YAML serialization methods
  • Added unit tests covering TOML writer behavior and serialization

Testing

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 1.X of the library, if so PR link:
  • My change applies to the version 2.X of the library, if so PR link:
  • My change applies to the version 3.X of the library, if so PR link:
  • I have evaluated the applicability of my change against the other versions above.

See the contributing guidelines for more information about how patches are applied across multiple versions.

Additional Notes

       Adds OpenApiTomlWriter (mirrors OpenApiJsonWriter / OpenApiYamlWriter),
       a new OpenApiConstants.Toml constant, and SerializeAsTomlAsync extension
       methods so callers can export an OpenAPI document as TOML.

       Public API declared in PublicAPI.Unshipped.txt; RS0026 suppressed for
       consistency with existing SerializeAsJson/YamlAsync overloads.
@Thyago-Oliveira-Perez Thyago-Oliveira-Perez requested a review from a team as a code owner April 17, 2026 00:52
@Thyago-Oliveira-Perez
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Thyago-Oliveira-Perez
Thank you for using the SDK and for reaching out.
Thanks for the contribution!

I'm a bit mixed on this proposal and wished you had started by creating an issue first to have a discussion.

OpenAPI descriptions are by design deeply nested, and TOML does not seem to be designed for that. Additionally, the ecosystem support for TOML, and demand for it is low to inexistant. (no prior issue on the matter)

As for this PR: I'm really questioning the usefulness of having the ability to serialize to, but not deserialize from TOML. I understand this might be useful to convert and push to other systems that only accept TOML, but I'd be surprised to see any system that only accepts TOML in 2026. Implementing the deserialization would need to be done in a companion library like yaml is done today. And would allow us to validate roundtrips actually work.

Before we make any further code changes, can you please expand on why you think TOML is necessary? Why it needs to be in the "official library" (and not in a community owned peer)? And what you're trying to achieve (beyond supporting TOML)?

Thanks!

@Thyago-Oliveira-Perez
Copy link
Copy Markdown
Author

Thanks for the feedback @baywet.

That’s fair, and I agree I should have opened an issue first.

The motivation here isn’t really adding TOML support for the sake of it, but solving a "problem" I'm having.

I’ve been using OpenAPI as input for AI-assisted workflows (mainly generating frontend code), and JSON/YAML aren’t great in that context. TOML ended up being better in that context as it is more predictable format and consume less tokens for prompts. So the idea is more about having a readable/export-friendly projection.

On serialization without deserialization, I agree it’s a limitation. My assumption was that this would behave more like an export format, but I see your point that proper support would likely require a companion package (like YAML).

Regarding being in the official library: my thinking was mostly around keeping it close to the existing serialization logic to avoid fragmentation, but I’m totally open to moving this to a separate/experimental package if that fits better.

Happy to open an issue and continue the discussion there if you prefer.

@baywet
Copy link
Copy Markdown
Member

baywet commented Apr 20, 2026

Hi @Thyago-Oliveira-Perez
Thank you for the additional information.

TOML ended up being better in that context as it is more predictable format and consume less tokens for prompts.

I'm not sure how that claim stands? Depending on the scenarios, and from cursory search, TOML appears to use the same number of characters (blank spaces excluded) than YAML or JSON. Except for deeply nested structures where it's worse. Do you have examples that would illustrate this?

On serialization without deserialization, I agree it’s a limitation. My assumption was that this would behave more like an export format, but I see your point that proper support would likely require a companion package (like YAML).

From an integration tests perspective, having the ability to roundtrip often leads to the discovery of defects, improving the quality.

Regarding being in the official library: my thinking was mostly around keeping it close to the existing serialization logic to avoid fragmentation, but I’m totally open to moving this to a separate/experimental package if that fits better.

I think it'd make more sense to have this a its own library for now. And if we start seeing a lot of demand for it, we'll evaluate moving things into this repository, does that make sense?

Let me know if you have any additional comments or questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants